// 0-1 背包
#include <algorithm>
#include <iostream>

using namespace std;

const int maxlen = 1010;
int n, x;
struct man {
    int lose;
    int win;
    int use;
    int gain;
} men[maxlen];
int s = 0;
int f[maxlen];

bool cmp(man m1, man m2) { return m1.gain < m2.gain; }

int main() {
    cin >> n >> x;
    for (int i = 0; i < n; i++) cin >> men[i].lose >> men[i].win >> men[i].use;
    for (int i = 0; i < n; i++) men[i].gain = men[i].win - men[i].lose, s += men[i].lose;
    sort(men, men + n, cmp);
    for (int j = 0; j < n; j++) {
        for (int i = x; i >= men[j].use; i--) {
            f[i] = max(f[i - men[j].use] + men[j].gain, f[i]);
        }
    }
    cout << (long long)(f[x] + s) * 5;
}